﻿using WindowsFormsApplication3;
using System.Windows.Forms;
using NUnit.Framework;
using NUnit.Extensions.Forms;
using System;


namespace GUI_Test
{
    public class Nunit
    {

        static Form1 form = null;
        static ControlTester TextBox = null;
        static ButtonTester btn1 = null;
        static ButtonTester btn2 = null;
        static ButtonTester btn3 = null;
        static ButtonTester btn4 = null;
        static ButtonTester btn5 = null;
        static ButtonTester btn6 = null;
        static ButtonTester btn7 = null;
        static ButtonTester btn8 = null;
        static ButtonTester btn9 = null;
        static ButtonTester btn0 = null;
        static ButtonTester btnMinus = null;
        static ButtonTester btnSum = null;
        static ButtonTester btnPlus = null;
        static ButtonTester btnDivide = null;
        static ButtonTester btnMultiply = null;

        [SetUp]
        public void Init()
        {
            form = new Form1();
            form.Show();

            TextBox = new ControlTester("ResultBox");
            btn1 = new ButtonTester("1");
            btn2 = new ButtonTester("2");
            btn3 = new ButtonTester("3");
            btn4 = new ButtonTester("4");
            btn5 = new ButtonTester("5");
            btn6 = new ButtonTester("6");
            btn7 = new ButtonTester("7");
            btn8 = new ButtonTester("8");
            btn9 = new ButtonTester("9");
            btn0 = new ButtonTester("0");
            btnMinus = new ButtonTester("-");
            btnSum = new ButtonTester("=");
            btnPlus = new ButtonTester("+");
            btnDivide = new ButtonTester("/");
            btnMultiply = new ButtonTester("*");
        }

        [TearDown]
        public void Cleanup()
        {
            form.Dispose();
        }

        [Test]
        public void CalcMinus()
        {
            //Actions
            btn9.Click();
            btnMinus.Click();
            btn6.Click();
            btnSum.Click();

            //Asserts
            int expected = 3;
            string txt = TextBox["Text"].ToString();
            int actual = Convert.ToInt32(txt);
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void CalcPlus()
        {
            //Actions
            btn9.Click();
            btnPlus.Click();
            btn6.Click();
            btnSum.Click();

            //Asserts
            int expected = 15;
            string txt = TextBox["Text"].ToString();
            int actual = Convert.ToInt32(txt);
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void CalcMultiply()
        {
            //Actions
            btn5.Click();
            btnMultiply.Click();
            btn6.Click();
            btnSum.Click();

            //Asserts
            int expected = 30;
            string txt = TextBox["Text"].ToString();
            int actual = Convert.ToInt32(txt);
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void CalcDivide()
        {
            //Actions
            btn9.Click();
            btnDivide.Click();
            btn3.Click();
            btnSum.Click();

            //Asserts
            int expected = 3;
            string txt = TextBox["Text"].ToString();
            int actual = Convert.ToInt32(txt);
            Assert.AreEqual(expected, actual);
        }
        /*
        [Test]
        //[ExpectedException(typeof(Exception), "DivideByZeroException")]
        public void CalcZeroDivide()
        {
            //Actions
            btn9.Click();
            btnDivide.Click();
            btn0.Click();
            btnSum.Click();
        }
         */
    }
}
